package org.jeecg.modules.iot.middleware.processor.powerOperate;


import org.jeecg.jt808.JTT808Message;
import org.jeecg.modules.iot.model.Jt808Control.Jt808CentralControlConfig;
import org.jeecg.modules.iot.model.modbus.ModbusParams;
import org.jeecg.modules.iot.middleware.processor.JT808MessageGenerator;
import org.jeecg.modules.iot.middleware.processor.MessageType;
import org.jeecg.modules.iot.middleware.util.ModbusRTUUtils;
import org.springframework.stereotype.Component;

@Component
public class SettingPowerMessageGenerator implements JT808MessageGenerator {

    @Override
    public String generateMessage(JTT808Message message) {
        return "";
    }

    @Override
    public String generateMessage(JTT808Message message, Jt808CentralControlConfig config) {
        return "";
    }

    @Override
    public String generateMessage(JTT808Message message, ModbusParams params) { // 添加 ModbusParams 参数
        byte transparentMsgType = (byte) 0xBA;
        int messageId=0x8900;
        return ModbusRTUUtils.generateModbusTransparentMessage(message, params, transparentMsgType, messageId);
    }

    @Override
    public String getType() {
        return MessageType.SETTING_POWER.name();
    }



    public static void main(String[] args) {
        SettingPowerMessageGenerator transparentMessageGenerator=new SettingPowerMessageGenerator();
        // 生成编码信息
        JTT808Message jtt808Message = new JTT808Message();
        jtt808Message.setSim("18251893334");
        jtt808Message.setSequence(111);
        // 创建 ModbusParams 对象
        ModbusParams params = new ModbusParams();
        params.setFunctionCode(ModbusParams.FunctionCode.READ_HOLDING_REGISTERS);
        params.setSlaveAddress(4);
        params.setStartAddress(1000);
        params.setRegisterCount(2);

// 调用 generateMessage 方法，传入 ModbusParams 对象

        String message = transparentMessageGenerator.generateMessage(jtt808Message, params);
        System.out.println(message);
    }



}